<?php

class Content_Model_Default extends MVC_Model
{

	public function menu($position = 'H')
	{
		$query = sprintf("SELECT *
							FROM content_menu
							WHERE menu_position = '%s'
								AND parent_id = 0
								AND posted = 'Y'
								ORDER BY sorted",
								$position);
		
		return $this->db->query($query);
	}
	
	public function subMenu($parentId)
	{
		$query = sprintf("SELECT *
							FROM content_menu
							WHERE parent_id = %d
								AND posted = 'Y'
								ORDER BY sorted",
								$parentId);
								
		return $this->db->query($query);
	}
	
	public function getMenuContentById($menuId)
	{
		$query = sprintf("SELECT cm.*, c.txt
							FROM content c
							INNER JOIN content_menu cm ON cm.id=c.menu_id
							WHERE cm.id=%d LIMIT 1", $menuId);
		//echo $query;
		$result=$this->db->query($query)->fetch();
		
		return $result;

		
	}
	
	public function indexPageContent()
	{
		$query = sprintf("SELECT cm.home_page, c.txt
							FROM content c
							INNER JOIN content_menu cm ON cm.id=c.menu_id
							WHERE cm.home_page='Y'");
		//echo $query;
		$result=$this->db->query($query);
		
		$html = '';
		
		$row = $result->fetch();
		
		$html .= stripslashes($row['txt']);
		
		
		return $html;
	}
}